#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int ret = 0, in = 10000, out = -1;
        for (auto i : prices)
        {
            if (out > i) ret += out - in, in = i, out = -1;
            else if (in >= i) in = i;
            else if (i > out) out = i;
        }
        if (out > in) ret += out - in;
        return ret;
    }
};